const XLSX = require('xlsx')

const workbook = XLSX.readFile('./input/数据对应关系.xlsx')
const getJSON = () => {
  // 获取工作表列表
  const sheetNames = workbook.SheetNames

  let jsonArray = []
  //遍历每个工作表并转换为JSON
  sheetNames.forEach(sheetName => {
    const worksheet = workbook.Sheets[sheetName]
    if (sheetName !== 'BA20') {
      let item = {
        name: sheetName,
      }
      const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 'A' })
      item.arr = jsonData.map(row => {
        // console.log(row);
        if (row['D']) {
          item.number = row['D']
          
        }
        return {
          title: row['A'], // A列的数据作为title属性
          content: row['B'], // B列的数据作为content属性
          step: row['C'], // C列的数据作为step属性
        }
      })
      jsonArray.push(item)
    }
  })
  return jsonArray
}

const getJSONoneSheet = sheetName => {
  //遍历每个工作表并转换为JSON
  const worksheet = workbook.Sheets[sheetName]
  return XLSX.utils.sheet_to_json(worksheet)
}
exports.getJSONoneSheet = getJSONoneSheet
exports.getJSON = getJSON
